﻿using System.Collections.ObjectModel;
using TestBat.IModels.Models;
using TestBat.IViewModels.Base;
using TestBat.IViewModels.Factories;
using TestBat.IViewModels.Workspaces.Schedules;

namespace TestBat.ViewModels.Workspaces.Schedules
{
    public class ScheduleListViewModel : ListViewModel<IScheduleViewModel, ObservableCollection<IScheduleViewModel>>, IScheduleListViewModel
    {
        public ScheduleListViewModel(IScheduleModel scheduleModel, IScheduleViewModelFactory scheduleViewModelFactory) : base(true)
        {
            this.scheduleModel = scheduleModel;
            this.scheduleViewModelFactory = scheduleViewModelFactory;
        }

        //[CheckUnsavedChanges]
        //protected override void ChangeSelected(IScheduleViewModel from, IScheduleViewModel to)
        //{
        //    base.ChangeSelected(from, to);
        //}

        protected override ObservableCollection<IScheduleViewModel> _RecreateItems()
        {
            ObservableCollection<IScheduleViewModel> list = new ObservableCollection<IScheduleViewModel>();

            foreach (var schedule in scheduleModel.GetAll())
            {
                IScheduleViewModel scheduleViewModel = scheduleViewModelFactory.Create(schedule);
                list.Add(scheduleViewModel);
            }

            return list;
        }

        private readonly IScheduleModel scheduleModel;
        private readonly IScheduleViewModelFactory scheduleViewModelFactory;
    }
}
